{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Generating Results on Datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "%matplotlib inline\n",
    "import os\n",
    "import sys\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams['figure.figsize'] = [14, 8]\n",
    "\n",
    "sys.path.append('../..')\n",
    "from pytracking.analysis.plot_results import plot_results, print_results, print_per_sequence_results\n",
    "from pytracking.evaluation import Tracker, get_dataset, trackerlist"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plots for OTB, NFS and UAV"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "trackers = []\n",
    "trackers.extend(trackerlist('atom', 'default', range(0,5), 'ATOM'))\n",
    "trackers.extend(trackerlist('dimp', 'dimp18', range(0,5), 'DiMP18'))\n",
    "trackers.extend(trackerlist('dimp', 'dimp50', range(0,5), 'DiMP50'))\n",
    "trackers.extend(trackerlist('dimp', 'prdimp18', range(0,5), 'PrDiMP18'))\n",
    "trackers.extend(trackerlist('dimp', 'prdimp50', range(0,5), 'PrDiMP50'))\n",
    "\n",
    "dataset = get_dataset('otb')\n",
    "plot_results(trackers, dataset, 'OTB', merge_results=True, plot_types=('success', 'prec'), \n",
    "             skip_missing_seq=False, force_evaluation=True, plot_bin_gap=0.05, exclude_invalid_frames=False)\n",
    "\n",
    "dataset = get_dataset('nfs')\n",
    "plot_results(trackers, dataset, 'NFS', merge_results=True, plot_types=('success', 'prec'), \n",
    "             skip_missing_seq=False, force_evaluation=True, plot_bin_gap=0.05, exclude_invalid_frames=False)\n",
    "\n",
    "dataset = get_dataset('uav')\n",
    "plot_results(trackers, dataset, 'UAV', merge_results=True, plot_types=('success', 'prec'), \n",
    "             skip_missing_seq=False, force_evaluation=True, plot_bin_gap=0.05, exclude_invalid_frames=False)\n",
    "\n",
    "dataset = get_dataset('otb', 'nfs', 'uav')\n",
    "plot_results(trackers, dataset, 'OTB+NFS+UAV', merge_results=True, plot_types=('success', 'prec'), \n",
    "             skip_missing_seq=False, force_evaluation=True, plot_bin_gap=0.05, exclude_invalid_frames=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plots for LaSOT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "trackers = []\n",
    "trackers.extend(trackerlist('atom', 'default', range(0,5), 'ATOM'))\n",
    "trackers.extend(trackerlist('dimp', 'dimp18', range(0,5), 'DiMP18'))\n",
    "trackers.extend(trackerlist('dimp', 'dimp50', range(0,5), 'DiMP50'))\n",
    "trackers.extend(trackerlist('dimp', 'prdimp18', range(0,5), 'PrDiMP18'))\n",
    "trackers.extend(trackerlist('dimp', 'prdimp50', range(0,5), 'PrDiMP50'))\n",
    "\n",
    "dataset = get_dataset('lasot')\n",
    "plot_results(trackers, dataset, 'LaSOT', merge_results=True, plot_types=('success'), \n",
    "             skip_missing_seq=False, force_evaluation=True, plot_bin_gap=0.05)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Tables for OTB, NFS, UAV and LaSOT"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "trackers = []\n",
    "trackers.extend(trackerlist('atom', 'default', range(0,5), 'ATOM'))\n",
    "trackers.extend(trackerlist('dimp', 'dimp18', range(0,5), 'DiMP18'))\n",
    "trackers.extend(trackerlist('dimp', 'dimp50', range(0,5), 'DiMP50'))\n",
    "trackers.extend(trackerlist('dimp', 'prdimp18', range(0,5), 'PrDiMP18'))\n",
    "trackers.extend(trackerlist('dimp', 'prdimp50', range(0,5), 'PrDiMP50'))\n",
    "\n",
    "dataset = get_dataset('otb')\n",
    "print_results(trackers, dataset, 'OTB', merge_results=True, plot_types=('success', 'prec', 'norm_prec'))\n",
    "\n",
    "dataset = get_dataset('nfs')\n",
    "print_results(trackers, dataset, 'NFS', merge_results=True, plot_types=('success', 'prec', 'norm_prec'))\n",
    "\n",
    "dataset = get_dataset('uav')\n",
    "print_results(trackers, dataset, 'UAV', merge_results=True, plot_types=('success', 'prec', 'norm_prec'))\n",
    "\n",
    "dataset = get_dataset('otb', 'nfs', 'uav')\n",
    "print_results(trackers, dataset, 'OTB+NFS+UAV', merge_results=True, plot_types=('success', 'prec', 'norm_prec'))\n",
    "\n",
    "dataset = get_dataset('lasot')\n",
    "print_results(trackers, dataset, 'LaSOT', merge_results=True, plot_types=('success', 'prec', 'norm_prec'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Filtered per-sequence results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Print per sequence results for sequences where all trackers fail, i.e. all trackers have average overlap in percentage of less than 10.0\n",
    "filter_criteria = {'mode': 'ao_max', 'threshold': 10.0}\n",
    "dataset = get_dataset('otb', 'nfs', 'uav')\n",
    "print_per_sequence_results(trackers, dataset, 'OTB+NFS+UAV', merge_results=True, filter_criteria=filter_criteria, force_evaluation=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Print per sequence results for sequences where at least one tracker fails, i.e. a tracker has average overlap in percentage of less than 10.0\n",
    "filter_criteria = {'mode': 'ao_min', 'threshold': 10.0}\n",
    "dataset = get_dataset('otb', 'nfs', 'uav')\n",
    "print_per_sequence_results(trackers, dataset, 'OTB+NFS+UAV', merge_results=True, filter_criteria=filter_criteria, force_evaluation=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Print per sequence results for sequences where the trackers have differing behavior.\n",
    "# i.e. average overlap in percentage for different trackers on a sequence differ by at least 40.0\n",
    "filter_criteria = {'mode': 'delta_ao', 'threshold': 40.0}\n",
    "dataset = get_dataset('otb', 'nfs', 'uav')\n",
    "print_per_sequence_results(trackers, dataset, 'OTB+NFS+UAV', merge_results=True, filter_criteria=filter_criteria, force_evaluation=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Print per sequence results for all sequences\n",
    "filter_criteria = None\n",
    "dataset = get_dataset('otb', 'nfs', 'uav')\n",
    "print_per_sequence_results(trackers, dataset, 'OTB+NFS+UAV', merge_results=True, filter_criteria=filter_criteria, force_evaluation=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}